<template>
	<div class="right_header_list">
		<span>{{ titleObj.title }}</span>
		<span class="change" @click="getContentOfChannel">
			<i class="iconfont" :class="titleObj.title_icon"></i>
			<span class="action">{{ titleObj.actionName }}</span>
		</span>
	</div>
	<div >
		<a :href="Path + item.url" class="right_card" v-for="(item, index) in contentList" :key="index">
			<div class="right_card_pic_content"><img class="right_card_pic" :src="getImgPath(item.headImag)" /></div>
			<div class="right_card_descript_content">
				<p class="right_card_descript_title">{{ item.title }}</p>
				<p class="right_card_descript_comment">
					<i class="iconfont icon-Comment"></i>
					<span class="right_card_descript_comment_number">{{ setNumber(item.comments || 0) }}</span>
				</p>
			</div>
		</a>
	</div>
</template>

<script>
export default {
	props: {
		titleObj: {
			title: '',
			title_icon: '',
			actionName: ''
		},
		curentChannelId: '',
	},
	data() {
		return {
			src: '../img/bg.jpg',
			currentPage: 0,
			contentList: [],
			Path:getRootPath(),
		};
	},
	watch: {
		curentChannelId: {
			handler(newVal, oldVal) {
				if (newVal != oldVal) {
					this.getContentOfChannel();
				}
			},
			deep: true
		}
	},
	mounted() {
		this.getContentOfChannel();
	},
	methods: {
		setNumber(val) {
			let value = val;
			if (value >= 1000) {
				value = value / 1000 + 'K';
			} else if (value >= 10000) {
				value = value / 1000 + 'W';
			}
			return value;
		},
		getContentOfChannel() {
			if (this.currentPage == 0 || this.currentPage == 2) {
				this.currentPage = 1;
			} else if (this.currentPage == 1) {
				this.currentPage = 2;
			}
			let param = {
				pageNum: this.currentPage,
				pageSize: 5
			};
			contentApi.fetchContentOfChannel(param, res => {
				if (res.code == '00000 00000') {
					this.contentList = res.data.records;
				} else {
				}
			});
		},
		getImgPath(url){
			return imgPath(url);
		},
	}
};
</script>

<style>
.right_header_list {
  height: fit-content;
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  width: 100%;
  font-size: 20px;
  font-family: PingFang SC-Medium, PingFang SC;
  font-weight: 500;
  color: #333333;
  line-height: 20px;
}
.right_header_list .change {
  font-size: 16px;
  font-weight: 400;
  color: #ff3333;
  cursor: pointer;
}
.right_card {
  display: flex;
  margin-bottom: 24px;
}
.right_card .right_card_pic_content {
  width: 120px;
  height: 68px;
  overflow: hidden;
  border-radius: 4px;
  position: relative;
  margin-right: 16px;
}
.right_card .right_card_pic_content .right_card_pic {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  margin: auto;
}
.right_card .right_card_pic_content .right_card_pic:hover {
  transform: scale(1.05);
  transition: all 0.1s linear;
}
.right_card .right_card_descript_content {
  display: flex;
  width: 182px;
  flex-direction: column;
  justify-content: space-between;
}
.right_card .right_card_descript_content .right_card_descript_title {
  font-size: 16px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: #333333;
  line-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  cursor: pointer;
}
.right_card .right_card_descript_content .right_card_descript_title:hover {
  color: #ff3333;
}
.right_card .right_card_descript_content .right_card_descript_comment {
  font-size: 12px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: #999999;
  line-height: 12px;
}
.right_card .right_card_descript_content .right_card_descript_comment .iconfont {
  font-size: 12px;
  color: #999;
}
.right_card .right_card_descript_content .right_card_descript_comment .right_card_descript_comment_number {
  margin-left: 2px;
}

</style>
